/*
 * Copyright 2008 Georgi Staykov
 * 
 * This file is part of pscoder.
 *
 * pscoder is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * pscoder is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with pscoder.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.gstaykov.pscoder.util;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

public class Logger {
    public static final String LOGGER_PLUGIN_ID = "com.gstaykov.powershell";
    private static Logger instance = new Logger();
    
    private ILog logger = null; 
    
    public Logger() {
        logger = ResourcesPlugin.getPlugin().getLog();
    }
    
    public void logInfo(String message) {
        Status status = new Status(IStatus.INFO, LOGGER_PLUGIN_ID, message);
        
        if (logger != null) {
            logger.log(status);
        } else {
            System.out.println(status);
        }
    }
    
    public void logError(String message, Exception e) {
        Status status = new Status(IStatus.ERROR, LOGGER_PLUGIN_ID, message, e);
        
        if (logger != null) {
            logger.log(status);
        } else {
            System.out.println(status);
        }
    }
    
    public static Logger getInstance() {
        return instance;
    }
}
